{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After downloading, install unrar on your computer\n",
    "$ sudo apt-get install unrar\n",
    "Unrar data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "path2data = \"./data\"\n",
    "sub_folder = \"hmdb51_org\"\n",
    "sub_folder_jpg = \"hmdb51_jpg\"\n",
    "path2aCatgs = os.path.join(path2data, sub_folder)\n",
    "\n",
    "listOfCategories = os.listdir(path2aCatgs)\n",
    "listOfCategories, len(listOfCategories)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for cat in listOfCategories:\n",
    "    print(\"category:\", cat)\n",
    "    path2acat = os.path.join(path2aCatgs, cat)\n",
    "    listOfSubs = os.listdir(path2acat)\n",
    "    print(\"number of sub-folders:\", len(listOfSubs))\n",
    "    print(\"-\"*50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import myutils"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "extension = \".avi\"\n",
    "n_frames = 16\n",
    "for root, dirs, files in os.walk(path2aCatgs, topdown=False):\n",
    "    for name in files:\n",
    "        if extension not in name:\n",
    "            continue\n",
    "        path2vid = os.path.join(root, name)\n",
    "        frames, vlen = myutils.get_frames(path2vid, n_frames= n_frames)\n",
    "        path2store = path2vid.replace(sub_folder, sub_folder_jpg)\n",
    "        path2store = path2store.replace(extension, \"\")\n",
    "        print(path2store)\n",
    "        os.makedirs(path2store, exist_ok= True)\n",
    "        myutils.store_frames(frames, path2store)\n",
    "    print(\"-\"*50)    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
